/*
 * Copyright 2016 Wealth Inc. All rights reserved.
 */
 package com.wealth.order.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.wealth.order.entity.Order;

import iaas.repository.BaseRepository;

/**
 * @author chan
 * @version 1.0
 * @since 1.0
 */
 
@Repository
public interface OrderDao extends BaseRepository<Order, Long> ,JpaSpecificationExecutor<Order>{

	/**  查询银行订单 下的商户订单 */
	public List<Order> findByOrderPlatId(Long orderPlatId);
	
	/** 商户月消费人数 */
	@Query(value="SELECT COUNT(id) FROM t_order WHERE paystatus=1 and merchant_id=?1 and create_time>=?2 and create_time<=?3",nativeQuery=true)
	public Integer avgConsumeNumberByMerchantId(Long merchantid,Date start,Date end) throws Exception;
	
	/** 商户平均消费 */
	@Query(value="SELECT AVG(total) FROM t_order WHERE merchant_id=?1 AND paystatus = 1",nativeQuery=true)
	public Integer avgTotalByMerchantId(Long merchantid) throws Exception;
	
	public Order findByOrderVirtualId(Long OrderVirtualId);
	
}
